package com.newtouch.avmarketing.mgr.modules.avmarkrting.model;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.hibernate.validator.constraints.Range;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;

/**
 * 通用分页请求
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
public class PageReq {
    @Range(min = 0, max = Integer.MAX_VALUE, message = "页码不能小于0")
    private int page;
    @Range(min = 1, max = Integer.MAX_VALUE, message = "页大小在需要大于1")
    private int limit;

    public Pageable pageable() {
        return PageRequest.of(page, limit);
    }

    public Pageable pageable(Sort sort) {
        return PageRequest.of(page, limit, sort);
    }
}
